/*
 * Filters.h
 *
 *  Created on: Feb 13, 2020
 *      Author: Yannick
 */

#ifndef FILTERS_H_
#define FILTERS_H_
#include "main.h"

#define M_PI		3.14159265358979323846

typedef struct biquad_constant_t{
	uint16_t fc;
	uint8_t q;
}biquad_constant_t;

enum {
    lowpass = 0,
    highpass,
    bandpass,
    notch,
    peak,
    lowshelf,
    highshelf
};

typedef struct Biquad
{
    uint8_t type;
    float a1, a2, b0, b1, b2;
    float f, Q, peakGain;		//f = fc/fs
    float d0, d1 ,d2;
}Biquad;

void BQ_Init(Biquad* bq,uint8_t type, float f, float Q, float peakGainDB);
void BQ_SetFc(Biquad* bq,float f);
float BQ_GetFc(Biquad* bq);
void BQ_SetQ(Biquad* bq,float Q);
float BQ_GetQ(Biquad* bq);
float BQ_Process(Biquad* bq,volatile float in) ; 
void BQ_SetBiquad(Biquad* bq,uint8_t type, float f, float Q, float peakGainDB);
void BQ_CalcBiquad(Biquad* bq);

#endif /* FILTERS_H_ */
